package com.indexingsystem.boss.utils;


import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import com.indexingsystem.boss.Vo.ResourceRelationInfoVo;


public class ListSortUtils
{
    public static void ListSort(List<ResourceRelationInfoVo> list)
    {
        Collections.sort(list, new Comparator<ResourceRelationInfoVo>()
        {
            @Override
            public int compare(ResourceRelationInfoVo o1, ResourceRelationInfoVo o2)
            {
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                try
                {
                    Date dt1 = format.parse(o1.getPublishDate());
                    Date dt2 = format.parse(o2.getPublishDate());
                    if (dt1.getTime() > dt2.getTime())
                    {
                        return 1;
                    }
                    else if (dt1.getTime() < dt2.getTime())
                    {
                        return -1;
                    }
                    else
                    {
                        return 0;
                    }
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
                return 0;
            }
        });
    }
}
